// Includes
#include "Process.h"
#include "ProcessManager.h"
#include "CreateWindowProcess.h"
#include "InitD3DProcess.h"
#include <windows.h>
#include <iostream>

// Global Vars
ProcessManager* gp_ProcessManager;

// Prototypes
bool CreateProcesses();
void RunProcesses();
void ShutdownProcesses();

// Win32 entry point
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
	// Create new process manager
	gp_ProcessManager = new ProcessManager();
	// Main Loop
	if (gp_ProcessManager != NULL && CreateProcesses())
	{
		RunProcesses();
	}
	ShutdownProcesses();
	system("PAUSE");
	return 0;
}
// END OF MAIN

// --------------------------------------------------------------- //

// Create and Attach Processes to main Process Manager:
bool CreateProcesses()
{	
	// CreateWindow
	StrongProcessPtr pCreateWindowProcess(new CreateWindowProcess());
	gp_ProcessManager->AttachProcess(pCreateWindowProcess);
	// Init D3D
	StrongProcessPtr pInitD3DProcess(new InitD3DProcess());
	gp_ProcessManager->AttachProcess(pInitD3DProcess);
	
	return true;
}

void RunProcesses()
{
	// Update all processes
	gp_ProcessManager->UpdateProcesses(0); 
}

void ShutdownProcesses()
{
	// Clear Process Manager
	gp_ProcessManager->~ProcessManager();
}